package com.youbar.client.impl;

import com.youbar.client.constant.CommonConstant;
import com.youbar.client.service.TokenService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

/**
 * Token 登录拦截处理
 */
@Service
public class TokenServiceImpl implements TokenService {

    @Override
    public boolean tokenValid(HttpServletRequest request) {
        String token = request.getHeader("token");
        String id = request.getHeader("id");
        if (token == null || token == "") {
            return false;
        }
        //判断
//        String tokenRedis = redisTemplate.opsForValue().get(CodeConstants.USER_L + id);
//        if (token.equals(tokenRedis)){
//            return true;
//        }
        return true;
    }

    @Override
    public boolean isExtraUrl(HttpServletRequest request) {
        String uri = request.getRequestURI();
        for (String o: CommonConstant.EXTRA_URI) {
            if (uri.startsWith(o)){
                return true;
            }
        }
        return false;
    }
}
